package io.api.modules.login.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.admin.common.service.impl.CrudServiceImpl;
import cn.hutool.core.util.StrUtil;
import io.admin.common.utils.ConvertUtils;
import io.api.modules.login.dao.EditionDao;
import io.api.modules.login.dto.EditionDTO;
import io.api.modules.login.entity.EditionEntity;
import io.api.modules.login.service.EditionService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 版本管理
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2024-07-08
 */
@Service
public class EditionServiceImpl extends CrudServiceImpl<EditionDao, EditionEntity, EditionDTO> implements EditionService {

    @Override
    public QueryWrapper<EditionEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<EditionEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }

    public EditionDTO selectNewest(Integer type) {
        //baseDao.selectObjs(new LambdaQueryWrapper<>().e)
        EditionEntity edition = baseDao.selectNewestByType(type);
        return ConvertUtils.sourceToTarget(edition, currentDtoClass());
    }

}